﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 新增仓库 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "SysPartner",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    Code = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    ErpId = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    Description = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    CommonState = table.Column<int>(type: "int", nullable: false),
                    UserId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    PartnerType = table.Column<int>(type: "int", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPartner", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysPartner_FrameworkUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "FrameworkUsers",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysWarehouse",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    Code = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    ErpId = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    Description = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    Location = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    IsVirtual = table.Column<bool>(type: "bit", nullable: false),
                    CommonState = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysWarehouse", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "SysOrgWarehouse",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    OrgId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    WarehouseId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysOrgWarehouse", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysOrgWarehouse_SysOrg_OrgId",
                        column: x => x.OrgId,
                        principalTable: "SysOrg",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysOrgWarehouse_SysWarehouse_WarehouseId",
                        column: x => x.WarehouseId,
                        principalTable: "SysWarehouse",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysWarehouseArea",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    Code = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    ErpId = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    WarehouseId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Description = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    CommonState = table.Column<int>(type: "int", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysWarehouseArea", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysWarehouseArea_SysWarehouseArea_ParentId",
                        column: x => x.ParentId,
                        principalTable: "SysWarehouseArea",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysWarehouseArea_SysWarehouse_WarehouseId",
                        column: x => x.WarehouseId,
                        principalTable: "SysWarehouse",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysWarehouseStocker",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    StockerId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    WarehouseId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysWarehouseStocker", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysWarehouseStocker_FrameworkUsers_StockerId",
                        column: x => x.StockerId,
                        principalTable: "FrameworkUsers",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysWarehouseStocker_SysWarehouse_WarehouseId",
                        column: x => x.WarehouseId,
                        principalTable: "SysWarehouse",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysWarehouseLocation",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    Code = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    ErpId = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    AreaId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    WarehouseId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Description = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    CommonState = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysWarehouseLocation", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysWarehouseLocation_SysWarehouseArea_AreaId",
                        column: x => x.AreaId,
                        principalTable: "SysWarehouseArea",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysWarehouseLocation_SysWarehouse_WarehouseId",
                        column: x => x.WarehouseId,
                        principalTable: "SysWarehouse",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysWarehouseStock",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    LocationId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    MaterialId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Quantity = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    SkuId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ErpId = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    BatchNumber = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    PartnerId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    StoreType = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysWarehouseStock", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysWarehouseStock_SysMaterialSku_SkuId",
                        column: x => x.SkuId,
                        principalTable: "SysMaterialSku",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysWarehouseStock_SysMaterial_MaterialId",
                        column: x => x.MaterialId,
                        principalTable: "SysMaterial",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysWarehouseStock_SysPartner_PartnerId",
                        column: x => x.PartnerId,
                        principalTable: "SysPartner",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysWarehouseStock_SysWarehouseLocation_LocationId",
                        column: x => x.LocationId,
                        principalTable: "SysWarehouseLocation",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysOrgWarehouse_OrgId",
                table: "SysOrgWarehouse",
                column: "OrgId");

            migrationBuilder.CreateIndex(
                name: "IX_SysOrgWarehouse_WarehouseId",
                table: "SysOrgWarehouse",
                column: "WarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPartner_UserId",
                table: "SysPartner",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_SysWarehouseArea_ParentId",
                table: "SysWarehouseArea",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_SysWarehouseArea_WarehouseId",
                table: "SysWarehouseArea",
                column: "WarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_SysWarehouseLocation_AreaId",
                table: "SysWarehouseLocation",
                column: "AreaId");

            migrationBuilder.CreateIndex(
                name: "IX_SysWarehouseLocation_WarehouseId",
                table: "SysWarehouseLocation",
                column: "WarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_SysWarehouseStock_LocationId",
                table: "SysWarehouseStock",
                column: "LocationId");

            migrationBuilder.CreateIndex(
                name: "IX_SysWarehouseStock_MaterialId",
                table: "SysWarehouseStock",
                column: "MaterialId");

            migrationBuilder.CreateIndex(
                name: "IX_SysWarehouseStock_PartnerId",
                table: "SysWarehouseStock",
                column: "PartnerId");

            migrationBuilder.CreateIndex(
                name: "IX_SysWarehouseStock_SkuId",
                table: "SysWarehouseStock",
                column: "SkuId");

            migrationBuilder.CreateIndex(
                name: "IX_SysWarehouseStocker_StockerId",
                table: "SysWarehouseStocker",
                column: "StockerId");

            migrationBuilder.CreateIndex(
                name: "IX_SysWarehouseStocker_WarehouseId",
                table: "SysWarehouseStocker",
                column: "WarehouseId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SysOrgWarehouse");

            migrationBuilder.DropTable(
                name: "SysWarehouseStock");

            migrationBuilder.DropTable(
                name: "SysWarehouseStocker");

            migrationBuilder.DropTable(
                name: "SysPartner");

            migrationBuilder.DropTable(
                name: "SysWarehouseLocation");

            migrationBuilder.DropTable(
                name: "SysWarehouseArea");

            migrationBuilder.DropTable(
                name: "SysWarehouse");
        }
    }
}
